home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / ANSI Headers / ios < prev    next >
Encoding:
Text File  |  1994-10-20  |  4.4 KB  |  190 lines  |  [TEXT/MMCC]

  1. // ios standard header
  2. #ifndef _IOS_
  3. #define _IOS_
  4. #include <exception>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8. #endif
  9.  
  10.   // I/O exception macros
  11. #if _CATCH_IO_EXCEPTIONS
  12.  #define _TRY_IO_BEGIN _TRY_BEGIN
  13.  #define _CATCH_IO_END _CATCH_ALL \
  14.  setstate(badbit); _RERAISE; _CATCH_END
  15.  #define _CATCH_IO_(x) _CATCH_ALL \
  16.  (x).setstate(ios::badbit); _RERAISE; _CATCH_END
  17. #else
  18.  #define _TRY_IO_BEGIN {
  19.  #define _CATCH_IO_END }
  20.  #define _CATCH_IO_(x) }
  21. #endif
  22. class ostream; class streambuf;
  23.   // class ios
  24. class ios {
  25. public:
  26.    // class failure
  27.  class failure : public xmsg {
  28.  public:
  29.   failure(const char *_X = 0, const char *_Y = 0,
  30.    const char *_Z = 0)
  31.    : xmsg(_X, _Y, _Z) {};
  32.   virtual ~failure();
  33.  protected:
  34.   virtual void do_raise();
  35.  };
  36.  enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  37.   uppercase = 0x0004, showbase = 0x0008,
  38.   showpoint = 0x0010, showpos = 0x0020,
  39.   left = 0x0040, right = 0x0080, internal = 0x0100,
  40.   dec = 0x0200, oct = 0x0400, hex = 0x0800,
  41.   scientific = 0x1000, fixed = 0x2000,
  42.   adjustfield = 0x01c0, basefield = 0x0e00,
  43.   floatfield = 0x3000, _Fmtmask = 0x3fff, _Fmtzero = 0};
  44.  enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  45.   failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  46.  enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  47.   app = 0x08, trunc = 0x10, binary = 0x20};
  48.  enum seekdir {beg = 0, cur = 1, end = 2};
  49.  _BITMASK(_Fmtflags, fmtflags);
  50.  _BITMASK(_Iostate, iostate);
  51.  _BITMASK(_Openmode, openmode);
  52.  typedef short io_state, open_mode, seek_dir;
  53.  enum _Uninitialized {_Noinit};
  54.    // class Init
  55.  class Init {
  56.  public:
  57.   Init();
  58.   ~Init();
  59.  private:
  60.   static int _Init_cnt;
  61.   };
  62.    // class _Iosarray
  63.  class _Iosarray {
  64.  public:
  65.   _Iosarray(int _Idx, _Iosarray *_Link = 0)
  66.    : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  67.   _Iosarray *_Next;
  68.   int _Index;
  69.   long _Lo;
  70.   void *_Vp;
  71.   };
  72.  ios(streambuf *_S)
  73.   {init(_S); }
  74.  ios(const ios& _R)
  75.   {init(0), *this = _R; }
  76.  ios& operator=(const ios&);
  77.  virtual ~ios();
  78.  operator void *() const
  79.   {return (void *)(!*this ? 0 : this); }
  80.  _Bool operator!() const
  81.   {return (((int)_State
  82.    & ((int)failbit|(int)badbit)) != 0); }
  83.  ios& copyfmt(const ios&);
  84.  ostream *tie() const
  85.   {return (_Tiestr); }
  86.  ostream *tie(ostream *);
  87.  streambuf *rdbuf() const
  88.   {return (_Sb); }
  89.  streambuf *rdbuf(streambuf *);
  90.  iostate rdstate() const
  91.   {return (_State); }
  92.  void clear(iostate = goodbit);
  93.  void clear(io_state _St)
  94.   {clear((iostate)_St); }
  95.  void setstate(iostate _St)
  96.   {clear((iostate)((int)_State | (int)_St)); }
  97.  void setstate(io_state _St)
  98.   {setstate((iostate)_St); }
  99.  _Bool good() const
  100.   {return (_State == goodbit); }
  101.  _Bool eof() const
  102.   {return ((int)_State & (int)eofbit); }
  103.  _Bool fail() const
  104.   {return ((int)_State
  105.    & ((int)badbit | (int)failbit)); }
  106.  _Bool bad() const
  107.   {return ((int)_State & (int)badbit); }
  108.  iostate exceptions() const
  109.   {return (_Except); }
  110.  void exceptions(iostate);
  111.  void exceptions(io_state _St)
  112.   {exceptions((iostate)_St); }
  113.  fmtflags flags() const
  114.   {return (_Fmtfl); }
  115.  fmtflags flags(fmtflags);
  116.  fmtflags setf(fmtflags);
  117.  fmtflags setf(fmtflags, fmtflags);
  118.  void unsetf(fmtflags);
  119.  int fill() const
  120.   {return (_Fillch); }
  121.  int fill(int);
  122.  int precision() const
  123.   {return (_Prec); }
  124.  int precision(int);
  125.  int width() const
  126.   {return (_Wide); }
  127.  int width(int);
  128.  static int xalloc()
  129.   {return (_Index++); }
  130.  long& iword(int _Idx)
  131.   {return (_Findarr(_Idx)._Lo); }
  132.  void *& pword(int _Idx)
  133.   {return (_Findarr(_Idx)._Vp); }
  134. protected:
  135.  ios()
  136.   {init(0); }
  137.  ios(_Uninitialized)
  138.   {}
  139.  void init(streambuf *);
  140. private:
  141.  streambuf *_Sb;
  142.  ostream *_Tiestr;
  143.  iostate _State, _Except;
  144.  fmtflags _Fmtfl;
  145.  int _Prec, _Wide;
  146.  char _Fillch;
  147.  static int _Index;
  148.  _Iosarray *_Arr;
  149.  _Iosarray& _Findarr(int);
  150.  void _Tidy();
  151.  };
  152. _BITMASK_OPS(ios::_Fmtflags)
  153. _BITMASK_OPS(ios::_Iostate)
  154. _BITMASK_OPS(ios::_Openmode)
  155.   // manipulators
  156. ios& dec(ios&);
  157. ios& fixed(ios&);
  158. ios& hex(ios&);
  159. ios& internal(ios&);
  160. ios& left(ios&);
  161. ios& noshowbase(ios&);
  162. ios& noshowpoint(ios&);
  163. ios& noshowpos(ios&);
  164. ios& noskipws(ios&);
  165. ios& nouppercase(ios&);
  166. ios& oct(ios&);
  167. ios& right(ios&);
  168. ios& scientific(ios&);
  169. ios& showbase(ios&);
  170. ios& showpoint(ios&);
  171. ios& showpos(ios&);
  172. ios& skipws(ios&);
  173. ios& uppercase(ios&);
  174.  
  175. #if __MWERKS__
  176. #pragma options align=reset
  177. #endif
  178.  
  179. #endif
  180.  
  181. /*
  182.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  183.  * Consult your license regarding permissions and restrictions.
  184.  */
  185.  
  186. /* Change log:
  187.  *94Oct03 Version received from PlumHall
  188.  *94Oct07 Inserted MW changes.
  189.  */
  190.